package com.atstudy.headline.web.admin.controller.login;

import com.atstudy.headline.login.LoginUserHolder;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.LoginService;
import com.atstudy.headline.web.admin.vo.login.LoginVo;
import com.atstudy.headline.web.admin.vo.users.UserLoginInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class loginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginVo LoginVo) {
        String jwt = loginService.login(LoginVo);
        return Result.ok( jwt );
    }

    /**
     * 获取用户个人信息
     * @param
     * @return
     *     */
    @GetMapping("/info")
    public Result<UserLoginInfoVo> info() {
        Integer userId = LoginUserHolder.getLoginUser().getUserId();
        UserLoginInfoVo userLoginInfoVo = loginService.getLoginUserInfoById(userId);
        return Result.ok(userLoginInfoVo);
    }



}
